import { DataSource } from "@/services/data-source";
import { getToken } from "@/utils";
import { invoke } from '@tauri-apps/api/core';
import { ConnectorDataSource } from "@/services/connector";

export const transformData = async (
    source: ConnectorDataSource,
    target: ConnectorDataSource,
    units: Array<any>,
    options: { [key: string]: any }
): Promise<any> => {
    // 
    let response: any = await invoke('plugin:mg-platform|transform_data', {
        source: source,
        target: target,
        units: units,
        options: options,
    });
    console.log(response);
    return response;
}

export interface DomainTransformerUnit {
    domain_identifier: string,
    classes?: string[],
}
export interface DomainTransformerFileOptions {
    version: string,
    format: string,
}
export interface DomainTransformerOptions {
    ignore_errs: boolean,
    file_options?: DomainTransformerFileOptions,
    ddl: boolean,
}

export const transformDomain = async (
    source: ConnectorDataSource,
    target: ConnectorDataSource,
    units: Array<DomainTransformerUnit>,
    options: DomainTransformerOptions
): Promise<any> => {
    // 
    let response: any = await invoke('plugin:mg-platform|transform_domain', {
        source: source,
        target: target,
        units: units,
        options: options,
    });
    console.log(response);
    return response;
}

export const transformDomainExport = async (
    source: ConnectorDataSource,
    target: string,
    units: Array<any>,
    options: { [key: string]: any }
): Promise<any> => {
    // 
    let response: any = await invoke('plugin:mg-platform|transform_domain_export', {
        source: source,
        target: target,
        units: units,
        options: {
            ...options,
            ddl: true
        },
    });
    console.log(response);
    return response;
}


export const transformDomainImport = async (
    source: string,
    target: ConnectorDataSource,
    units: Array<any>,
    options: { [key: string]: any }
): Promise<any> => {
    // 
    let response: any = await invoke('plugin:mg-platform|transform_domain_import', {
        source: source,
        target: target,
        units: units,
        options: options,
    });
    console.log(response);
    return response;
}


export const transformDomainClear = async (
    domains: Array<string>,
): Promise<any> => {
    // 
    let response: any = await invoke('plugin:mg-platform|transform_domain_clear', {
        domains: domains,
    });
    console.log(response);
    return response;
}

export const transformDomainDelete = async (
    domains: Array<string>,
): Promise<any> => {
    // 
    let response: any = await invoke('plugin:mg-platform|transform_domain_delete', {
        domains: domains,
    });
    console.log(response);
    return response;
}